package com.yhny.lykj.yuhannongye.Adapter;

import android.content.res.Resources;
import android.net.Uri;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.longsichao.lscframe.view.LSCImageView;
import com.yhny.lykj.yuhannongye.R;
import com.yhny.lykj.yuhannongye.app.BaseRefreshListAdapter;
import com.yhny.lykj.yuhannongye.model.ShopListModel;

import java.util.List;

/**
 * ShopListAdapter
 * 商城列表
 */
public class ShopListAdapter extends BaseRefreshListAdapter<ShopListAdapter.ViewHolder> {
    private List<ShopListModel.ListEntity> list;
    private OnItemClickListener listener = null;
    private int selectedPosition = -1;// 选中的位置
    public ShopListAdapter(List<ShopListModel.ListEntity> list) {
        this.list = list;
    }

    @Override
    public void setOnItemClickListener(OnItemClickListener listener) {
        this.listener = listener;
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    @Override
    protected void onBindBaseViewHolder(ViewHolder holder, int position) {
        final ShopListModel.ListEntity entity = list.get(position);
        holder.nameView.setText(""+entity.name);

//        holder.textView.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
            holder.textView.setText("￥"+entity.goodsprice+"");

        Resources resources = holder.nameView.getContext().getResources();
        int height = resources.getDimensionPixelOffset(R.dimen.item_home_hot_height);
        int width = resources.getDimensionPixelOffset(R.dimen.item_home_hot_height);
        String imageUrl = "";
        if (!TextUtils.isEmpty(entity.goodspic)) {
            imageUrl = entity.goodspic;
        }
        if (!TextUtils.isEmpty(imageUrl)) {
            holder.imgView.setPlaceHolder(R.drawable.normal_pic).setType(LSCImageView.Type.Normal).setTargetSize(width, height).setImageURI(Uri.parse(imageUrl));
        }else{
            holder.imgView.setImageResource(R.drawable.normal_pic);
        }
    }

    @Override
    protected int getLayoutResId(int viewType) {
        return R.layout.item_shop_list;
    }

    @Override
    protected ViewHolder onCreateBaseViewHolder(View itemView) {
        return new ViewHolder(itemView, listener);
    }
    public void setSelectedPosition(int position) {
        selectedPosition = position;
    }
    public static class ViewHolder extends BaseRefreshListAdapter.ViewHolder {

        private TextView nameView;
        private TextView numView;
        private TextView textView;
        private LSCImageView imgView;

        public ViewHolder(View itemView, OnItemClickListener listener) {
            super(itemView, listener);
            nameView = (TextView) itemView.findViewById(R.id.item_title);
            textView = (TextView) itemView.findViewById(R.id.item_text);
            imgView = (LSCImageView) itemView.findViewById(R.id.item_img);
        }
    }
}
